SWAGOLX.EXE (c) 1993 GDSOFT ALL RIGHTS RESERVED 00002 1 08-24-9413:34ALL ERIC MILLER Encryption Routine SWAG9408 ┘_v 12 e├ {π JM> FUNCTION ConvertTxt (S : String) : String;π JM> Var X : Byte;π JM> Beginπ JM> ConvertTxt[0] := S[0];π JM> For X := 1 to Length(S) doπ JM> ConvertTxt[X] := Chr(Ord(S[X]) XOR (Random(128) or 128));π JM> End;π JM> To encrypt a string, you just call ConvertTxt(string). Callπ JM> the function again, with the same parameters to decrypt.π JM> Anyone have anything better, or have any suggestions?ππ Here is basically the same function again. However note theπ RandSeed assignment - RandSeed is set to the length of theπ string before a string is processed. Since the length ofπ the string never changes, you can randomly pick any stringπ and be able to decrypt it. RandSeed is used to make Randomπ return a specific sequence of psuedo-random numbers, andπ this encryption method relies on the same sequence in orderπ for it to decrypt.π }ππ PROCEDURE EnDecrypt(VAR S: String);π VARπ X: Byte;π BEGINπ RandSeed := Length(S);π FOR X := 1 TO Length(S) DOπ S[X] := Chr(Ord(S[X]) XOR (Random(128) OR 128));π END;ππ VARπ S: String;π BEGINπ Write('Enter a string: ');π Readln(S);π EnDecrypt(S);π WriteLn;π WriteLn;π Writeln('The encrypted string is ', S);π EnDecrypt(S);π WriteLn;π WriteLn;π Writeln('The decrypted string is ', S);π END.ππ 2 08-24-9413:42ALL RICH VERAA Store Hidden Text SWAG9408 Æüí 75 e├ {π HIDESTR -- Rich Veraa's Anti-hack string hider.ππ Released to the Public Domaimπ 22 April, 1992π by Richard P. VeraaπππINTRODUCTIONππ The purpose of HIDESTR is to encrypt string variables in a Turboπ Pascal <tm> program so that they will be hidden in the .EXE fileπ and will make things a bit more difficult for hackers.ππ HIDESTR reads an ASCII list of text strings used in the program andπ creates Turbo Pascal <tm> source code for a TPU unit that includesπ the strings encrypted as constant arrays of bytes. There is aπ decrypting procedure to be used at run time to return the decryptedπ strings as functions.ππ To use HIDESTR, justππ 1. list the text strings to be used by the program in a text fileπ named LIST with numbered lines, as follows:ππ1 Myprogπ2 Version 1.0π3 by John Doeπ4 Enter velocity, mph:π5 Enter time of trip, hours:π6 The distance traveled isπ7 miles.π8 Do you wish to go on [Y/n]?π9 Doneπ10 Thank you for using MYPROGππ 2. Then write your program using str1, str2, str3, etc in place ofπ the strings.ππ 4. Place the TPU name "STRLIST" in your "uses" statement. Theπ following is code for a typical small program:ππProgram Myprog;πuses strlist;ππvarπ v, t, d : real;π ch : char;ππbeginπ ch := 'y';π writeln (srt1,' ',srt2);π writeln(str3);π writeln;π while not ch in ['n','N'] doπ beginπ write(str4,' ');π readln(v);π write(str5,' ');π readln(t);π writeln;π d := v * t;π writeln(str6,' ',d);π end;π writeln;π write(str8,' ');π readln(ch);π writeln;π writeln(str9);π writeln(str10);πend.πππ 5. Run HIDESTR in the same directory as the file LIST, with anyπ valid longint on the command line. The longint is the key forπ encrypting the strings, and functions as randseed for the Turboπ random number generator, whose output is added to the strings toπ encode them byte by byte;ππ HIDESTR will generate TP source code for the STRLIST.TPU, which mayπ be compiled with the program. The strings will appear in theπ resulting EXE file as arrays of random-appearing bytes.ππ The encryption technique is admittedly crude, and you may wish toπ improve on it, but It would take a very determined hacker to takeπ the trouble to unscramble this.ππprogram hidestr; {v 1.2}π{ By Richard Veraa }π{ Villa Maria, Room 211 }π{ 1050 NE 125 Street }π{ N. Miami, FL 33161 }π{ released into the public domain, April 23, 1992 }πuses crt;πconstπ key : longint = 1111111; {default encryption key}π {change to any number}πtypeπ stringptr = ^string;π byteptr = ^byte;π bytearray = array[1..255] of byte;ππvarπ str : array[1..255] of stringptr;π l : array[1..255] of byteptr;π th : array[1..255] of boolean;π n : integer;π ba : bytearray;π i, j : integer;π f2 : text;π spacecount : integer;π x, y : byte;π keystring : string;π code : integer;ππ procedure crypt(var b : bytearray; l : byte);π {Add random number to each byte}π varπ i : integer;π r : byte;π save : byte;π beginπ randseed := key;π for i := 1 to l doπ beginπ r := random(255);π b[i] := b[i] + r;π end;π end;ππ procedure decrypt(var b : bytearray; l : byte);π {Subtract number from each byte}π varπ i : integer;π r : byte;π beginπ randseed := key;π for i := 1 to l doπ beginπ r := random(255);π b[i] := b[i] - rπ end;π end;ππ procedure readfile;π varπ f : text;π s : string;π len, i : integer;π beginπ n := 0;π assign(f,'list');π reset(f);π while not eof(f) doπ beginπ inc(n);π read(f,i); {read line number}π if i <> n thenπ beginπ Writeln('Error in LIST.');π Writeln(' -- Numbering incorrect at line ',n);π Writeln;π Halt(n);π end;π readln(f,s); {read string}π while s[1] = chr( $20) do {remove leading blanks}π beginπ len := length(s);π dec(len);π for i := 1 to len doπ s[i] := s[i+1];π s[0] := chr(len);π end;π str[n]^ := s;π l[n]^ := length(str[n]^)π end;π close(f);π end;πππvarπ s : string;ππbeginπ clrscr;π writeln('Rich Veraa''s little string hider unit maker');π writeln('Version 1.2');ππ writeln;π if paramcount > 0 then {check for key on command line}π beginπ keystring := paramstr(1);π val(keystring,key,code);π if code <> 0 thenπ beginπ writeln('Parameter should be key in form longint');π writeln(' * * * Parameter error ',code,' * * * ');π writeln;π halt(code);π end;π end;π x := wherex;π y := wherey;π for i := 1 to 255 do {allocate memory}π beginπ new(str[i]);π new(l[i]);π end;π for i := 1 to 255 do {initialize}π beginπ th[i] := false;π l[i]^ := 0;π str[i]^ :='';π end;π readfile; {read LIST}π for i := 1 to 255 do {set lengths for arrays to hold strings}π beginπ for j := 1 to 255 doπ if l[i]^ = j then th[j] := true;π end;π assign(f2,'strlist.pas'); {write source code for strlist.pas}π rewrite(f2);π writeln(f2,'unit strlist;');ππ writeln(f2,'interface');ππ writeln(f2,'type'); {type statement}π writeln(f2,' bytearray = array[1..255] of byte;');π for i := 1 to 255 do {type arrays for encrypted strings}π if th[i] then writeln(f2,' t',i,' = string[',i,'];');ππ writeln(f2,'const');π writeln(f2,' n = ',n,';');π writeln(f2,' key = ',key,';');π for i := 1 to n do if l[i]^ > 1 thenπ beginπ for j := 1 to l[i]^ do {place string in array of byte}π ba[j] := ord(str[i]^[j]);π crypt(ba,l[i]^); {encrypt bytes in array}π gotoxy(x,y);π write('Encrypted ',i,' strings.');π spacecount := 34;π write(f2,' cr',i,' : array[1..',l[i]^,'] of byte = (');π for j := 1 to l[i]^ do {list array as constant in strlist.pas}π beginπ write(f2,ba[j]);π inc(spacecount,2);π if ba[j] > 9 then inc(spacecount);π if ba[j] > 99 then inc(spacecount);π if (spacecount > 72) and (j < l[i]^) thenπ beginπ writeln(f2,',');π write(f2,' ');π spacecount := 10;π endπ else if j < l[i]^ then write(f2,',');π end; {for j}π writeln(f2,');');π end; {for i}π writeln;π writeln;π x := wherex;π y := wherey;ππ writeln(f2,' procedure decrypt(var b : bytearray; l : byte);');π for i := 1 to n do if l[i]^ > 1 thenπ beginπ writeln(f2,' function str',i,' : t',l[i]^,';');π end;ππ writeln(f2,'implementation');π {write source code for decrypt procedure}ππ writeln(f2,' procedure decrypt(var b : bytearray; l : byte);');π writeln(f2,' var');π writeln(f2,' i : integer;');π writeln(f2,' r : byte;');π writeln(f2,' begin');π writeln(f2,' randseed := key;');π writeln(f2,' for i := 1 to l do');π writeln(f2,' begin');π writeln(f2,' r := random(255);');π writeln(f2,' b[i] := b[i] - r;');ππ writeln(f2,' end;');π writeln(f2,' end;');ππ for i := 1 to n do if l[i]^ > 1 thenπ beginπ {write source code for function to return string}π writeln(f2,' function str',i,' : t',l[i]^,';');π writeln(f2,' var');π writeln(f2,' ba : bytearray;');π writeln(f2,' j : integer;');π writeln(f2,' s : string;');π writeln(f2,' begin');π writeln(f2,' for j := 1 to ',l[i]^,' do');π writeln(f2,' ba[j] := cr',i,'[j];');π writeln(f2,' decrypt(ba, ',l[i]^,');');π writeln(f2,' for j := 1 to ',l[i]^,' do');π writeln(f2,' s[j] := chr(ba[j]);');π writeln(f2,' s[0] := chr(',l[i]^,');');π writeln(f2,' str',i,' := s;');π writeln(f2,' end;');π gotoxy(x,y);π write('String functions coded: ',i);ππ end;π gotoxy(x,y);π writeln;π writeln;ππ writeln(f2,'begin');ππ writeln(f2,'end.');π close(f2);π writeln('DONE');π for i := 1 to 255 do {dispose}π beginπ dispose(str[i]);π dispose(l[i]);π end;π writeln;πend.π